import request from "@/utils/request";

/**@skuInfoItemType 根据spuId获取sku详细信息的类型*/
export interface skuInfoItemType {
  id?: number;
  spuId?: number;
  price: number;
  skuName: string;
  skuDesc: string;
  weight: string;
  tmId?: number;
  category3Id: number | null;
  skuDefaultImg: string;
  isSale?: number;
  createTime?: string;
  skuImageList: skuImageListType | null;
  skuAttrValueList: skuAttrValueListType | null;
  skuSaleAttrValueList: skuSaleAttrValueListType | null;
}

/**@skuInfoListType 根据spuId获取的sku列表类型*/
export type skuInfoListType = skuInfoItemType[];

/**@skuImageItemType sku详细信息中sku图片列表skuImageList某一项的类型*/
export interface skuImageItemType {
  id?: number;
  skuId?: number;
  imgName: string;
  imgUrl: string;
  spuImgId?: number;
  isDefault?: string;
}

/**@skuImageListType sku详情中 sku图片列表的类型*/
export type skuImageListType = skuImageItemType[];

/**@skuAttrValueItemType sku详情中 sku的属性值列表中某一项的类型*/
export interface skuAttrValueItemType {
  id?: number;
  attrId?: number;
  valueId?: number;
  skuId?: number;
  attrName?: string;
  valueName?: string;
}

/**@skuAttrValueListType sku的属性值列表类型*/
export type skuAttrValueListType = skuAttrValueItemType[];

/**@skuSaleAttrValueItemType sku详情中 sku所拥有的的销售属性列表中某一项的值的类型*/
interface skuSaleAttrValueItemType {
  id?: number;
  skuId?: number;
  spuId?: number;
  saleAttrValueId?: number;
  saleAttrId?: number;
  saleAttrName?: string;
  saleAttrValueName?: string;
}

/**@skuSaleAttrValueListType  sku所拥有的销售属性列表类型*/
export type skuSaleAttrValueListType = skuSaleAttrValueItemType[];

/**@skuPageListType sku分页列表数据*/
export interface skuPageListType {
  total: number;
  size: number;
  current: number;
  searchCount: boolean;
  pages: number;
  records: skuInfoListType;
}

/**@requestCancelSale  根据skuId下架某个商品*/
export const requestCancelSale = (skuId: number) => {
  return request.get<any, null>(`/admin/product/cancelSale/${skuId}`);
};
/**@requestOnSale  根据skuId上架某个商品*/
export const requestOnSale = (skuId: number) => {
  return request.get<any, null>(`/admin/product/onSale/${skuId}`);
};

/**@requestDeleteSku 根据skuId删除某个商品*/
export const requestDeleteSku = (skuId: number) => {
  return request.delete<any, null>(`/admin/product/deleteSku/${skuId}`);
};

/**@requestFindBySpu 根据spuId获取它的spu列表*/
export const requestFindBySpu = (spuId: number) => {
  return request.get<any, skuInfoListType>(
    `/admin/product/findBySpuId/${spuId}`
  );
};

/**@requestFindBySku 根据skuId获取它的sku列表*/
export const requestFindBySku = (skuId: number) => {
  return request.get<any, skuInfoItemType>(
    `/admin/product/getSkuById/${skuId}`
  );
};

/**@requestSkuList 获取分页列表*/
export const requestSkuList = (page: number, limit: number) => {
  return request.get<any, skuPageListType>(
    `/admin/product/list/${page}/${limit}`
  );
};

/**@requestSaveSkuInfo 新增sku*/
export const requestSaveSkuInfo = (skuInfo: skuInfoItemType) => {
  return request.post<any, null>(`/admin/product/saveSkuInfo`, skuInfo);
};
